package org.imsetal.ilchatservice.controller;


import jakarta.annotation.Resource;
import lombok.Data;
import org.imsetal.ilapi.utils.Result;
import org.imsetal.ilchatservice.pojo.Dialogue;
import org.imsetal.ilchatservice.service.ChatService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

@RestController
@RequestMapping("/chat")
public class ChatController {
    @Resource
    private ChatService chatService;

    @PostMapping(value="sendMessage", produces= MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<Result> sendMessage(@RequestBody JSONSendMessage jsonSendMessage) {
        return chatService.getReply(jsonSendMessage.userid, jsonSendMessage.dialogueid, jsonSendMessage.model, jsonSendMessage.message)
                .map(Result::success);
    }

    @GetMapping("getUserAllDialogue")
    public Mono<Result> getUserAllDialogue(@RequestParam Long userid) {
        return chatService.getUserAllDialogue(userid)
                .map(Result::success);
    }
}

@Data
class JSONSendMessage{
    Long userid;
    Long dialogueid;
    String model;
    String message;
}
